package 客户复习;

public class PolymorphicDemo {
    public static void main(String[] args) {
//     /*   Dog o1=new Dog("小黑",2,"黑");
//        Animal o2 =new Dog("小黑",2,"黑");
//        Animal o3=new Chick("小花",1,"花");
//        Animal o4=new Fish("小金",3,"金");*/
        /*Master master=new Master();
        Animal o1 =new Dog("小黑",2,"黑");
        Animal o2=new Chick("小花",1,"花");
        Animal o3=new Fish("小金",3,"金");
        master.feed(o1);
        master.feed(o2);
        master.feed(o3);
*/
        Animal[] animals =new Animal[3];
        animals[0]=new Dog("小黑",2,"黑");
        animals[1]=new Fish("小金",3,"金");
        animals[2]=new Chick("小花",1,"花");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog ){
                Dog dog=(Dog) animals[i];
                dog.lookHome();
            }

            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.LayEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s=(Swim) animals[i];
                s.swim();
            }
        }

        /*Animal o=new Dog("小黑",2,"黑");
        Dog g=(Dog) o;
        Swim s=(Swim) o;
        System.out.println(o instanceof Dog);
        Animal o1=new Fish("小金",3,"金");
        Fish sh =(Fish) o1;
        Swim sm =(Swim) o1;
        System.out.println(o1 instanceof  Fish);
        System.out.println(o1 instanceof Swim);*/
    }
}
